//
//  UIImage+Circle.m
//  绘图
//
//  Created by 吴志勇 on 2020/3/25.
//  Copyright © 2020 wzy. All rights reserved.
//

#import "UIImage+Circle.h"

@implementation UIImage (Circle)


+ (UIImage *)imageWithBorder:(CGFloat)borderW color:(UIColor *)borderColor image:(UIImage *)image{
    //开启y图片的上下文 需要把起点移到边框的原点
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(image.size.width + 2*borderW, image.size.height + 2*borderW), NO, 0);
    //绘制外环圆
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width + 2*borderW, image.size.height + 2 * borderW)];
    [[UIColor redColor] set];
    [path fill]; // stroke环
    //设置裁剪区域，画笔需要移到图片的原点
    UIBezierPath *clipPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(borderW, borderW, image.size.width, image.size.height)];
    [clipPath addClip];
    [image drawAtPoint:CGPointMake(borderW, borderW)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

@end
